import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class JerrySend implements Runnable {
	DatagramSocket ds = null;
	public JerrySend(DatagramSocket ds) {
		this.ds = ds;
	}

	@Override
	public void run() {
		// 从键盘收字符
		BufferedReader br = null;
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			String str = "";
			while ((str = br.readLine()) != null) {
				byte[] buf = str.getBytes();// 接收到数据之后变成字符数组封装于包
				DatagramPacket dp = new DatagramPacket(buf, buf.length, InetAddress.getByName("171.88.73.17"), 9994);
				ds.send(dp);
				if ("over".equalsIgnoreCase(str)) {
					break;
				}
			}
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				br.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}